package LoginPackage;




import org.testng.annotations.Test;

import PagePackage.MyPageFactory;
import PagePackage.internalPageClass;
import PagePackage.loginPageClass;
import PagePackage.newUserPageClass;
import PagePackage.userRolePageClass;
import PagePackage.userContactInfoPageClass;
import PagePackage.usersPageClass;





public class NewUserClass extends TestBaseClass{

	
	

	@Test (priority=0)
  public void AdminCreatesNewCoach() {
		
		goToMainPage();
		checkPage();
		MyPageFactory.getPage(driver, loginPageClass.class).loginAs(adminEmail, adminPassword);
		MyPageFactory.getPage(driver, newUserPageClass.class ).createNewUser(adminCreatesNewCoachfirstName, adminCreatesNewCoachlastName, coachEmail, adminCreatesNewCoachphone1, adminCreatesNewCoachphone2)
		 
	     .chooseRole(headCoachrole)
		 .chooseSport(basketballSport);
		 
		 MyPageFactory.getPage(driver, userRolePageClass.class ).chooseTeam("Basketball Team")
		 .addRole()
	     .saveRole()
	     .findUserByEmail(coachEmail)
		 .scrollAndClick(0, 0, "//*[text()='"+coachEmail+"']");
		 driver.get("https://www-dev.krossover.com/intelligence-qa/teams");
		 MyPageFactory.getPage(driver, internalPageClass.class).logout();
		 
		 }
		 
	
	@Test (priority=1)
	public void AdminCancelsNewUserCreation() {
		
		goToMainPage();
		checkPage();
		MyPageFactory.getPage(driver, loginPageClass.class).loginAs(adminEmail, adminPassword);
		MyPageFactory.getPage(driver, newUserPageClass.class ).createNewUser(adminCreatesNewCoachfirstName, adminCreatesNewCoachlastName, cancelUserCreationemail,cancelUserCreationphone1, cancelUserCreationphone2);
		MyPageFactory.getPage(driver, userContactInfoPageClass.class ).canceluser.click();
		MyPageFactory.getPage(driver, usersPageClass.class ).findUserByEmail(cancelUserCreationemail)
		.scrollAndClick2(0, 0, "//*[text()='"+cancelUserCreationemail+"']");
		driver.get("https://www-dev.krossover.com/intelligence-qa/teams");
		 MyPageFactory.getPage(driver, internalPageClass.class).logout();
		
	 }

	
	
	@Test (priority=2)
	public void AdminCreatesAssistantCoach() {
		
		goToMainPage();
		checkPage();
		MyPageFactory.getPage(driver, loginPageClass.class).loginAs(adminEmail, adminPassword);
		MyPageFactory.getPage(driver, newUserPageClass.class ).createNewUser(adminCreatesAsCoachfirstName, adminCreatesAsCoachlastName, assistantCoachEmail, adminCreatesAsCoachphone1, adminCreatesAsCoachphone2)
		.chooseRole(asCoachrole)
		.chooseSport(footballSport)
		.chooseTeam(highschoolteam)
		.addRole()
		.saveRole();
		MyPageFactory.getPage(driver, usersPageClass.class ).findUserByEmail(assistantCoachEmail)
		.scrollAndClick(0, 0, "//*[text()='"+assistantCoachEmail+"']");
		driver.get("https://www-dev.krossover.com/intelligence-qa/teams");
		 MyPageFactory.getPage(driver, internalPageClass.class).logout();
	}
	
	
   
	
	@Test (priority=3)
	public void AdminCreatesIndexer() {
		
		goToMainPage();
		checkPage();
		MyPageFactory.getPage(driver, loginPageClass.class).loginAs(adminEmail, adminPassword);
		MyPageFactory.getPage(driver, newUserPageClass.class ).createNewUser(adminCreatesIndexerfirstName, adminCreatesIndexerlastName, indexerEmail, adminCreatesIndexerphone1, adminCreatesIndexerphone2)
		.chooseRole(indexerRole);
		MyPageFactory.getPage(driver, userRolePageClass.class).BasketballIndexingBox.click();
		MyPageFactory.getPage(driver, userRolePageClass.class).FootballIndexingBox.click();
		MyPageFactory.getPage(driver, userRolePageClass.class).LacrosseIndexingBox.click();
		MyPageFactory.getPage(driver, userRolePageClass.class).BasketballQABox.click();
		MyPageFactory.getPage(driver, userRolePageClass.class).FootballQABox.click();
		MyPageFactory.getPage(driver, userRolePageClass.class).LacrosseQABox.click();
		MyPageFactory.getPage(driver, userRolePageClass.class).addroleButton.click(); //click Add New Role button
		MyPageFactory.getPage(driver, userRolePageClass.class).saveRole()
	    .findUserByEmail(indexerEmail)
		.scrollAndClick(0, 0, "//*[text()='"+indexerEmail+"']");
		driver.get("https://www-dev.krossover.com/intelligence-qa/teams");
		 MyPageFactory.getPage(driver, internalPageClass.class).logout();
		
		
		
		
			 
	}
	
	@Test (priority=4)
	public void AdminCreatesAthlete() {
		
		goToMainPage();
		checkPage();
		MyPageFactory.getPage(driver, loginPageClass.class).loginAs(adminEmail, adminPassword);
		MyPageFactory.getPage(driver, newUserPageClass.class ).createNewUser(adminCreatesAthletefirstName, adminCreatesAthletelastName, athleteEmail, adminCreatesAthletephone1, adminCreatesAthletephone2)
		.chooseRole(athleterole);
	    //driver.findElement(By.xpath("//*[contains(.,'Only coaches can add an athlete to a team roster')]"));
         
         
         MyPageFactory.getPage(driver, userRolePageClass.class).addroleButton.click(); //click Add New Role button
		 
 		MyPageFactory.getPage(driver, userRolePageClass.class).saveRole()
 		  .findUserByEmail(athleteEmail)
 		.scrollAndClick(0, 0, "//*[text()='"+athleteEmail+"']");
 		driver.get("https://www-dev.krossover.com/intelligence-qa/teams");
		 MyPageFactory.getPage(driver, internalPageClass.class).logout();
 		
        
 		
	
} 
	
	
	@Test (priority=5)
	public void AdminRemovesRoles() {
		
		goToMainPage();
		checkPage();
		MyPageFactory.getPage(driver, loginPageClass.class).loginAs(adminEmail, adminPassword);
		MyPageFactory.getPage(driver, newUserPageClass.class ).createNewUser(adminRemovesRolesfirstName, adminCreatesAthletelastName, adminRemovesRolesemail, adminRemovesRolesphone1, adminRemovesRolesphone2)
	    .chooseRole(athleterole);
		MyPageFactory.getPage(driver, userRolePageClass.class).addroleButton.click();
		
    
		 
		MyPageFactory.getPage(driver, userRolePageClass.class).chooseRole(indexerRole);
		MyPageFactory.getPage(driver, userRolePageClass.class).addroleButton.click(); //click Add New Role button
		
		
		MyPageFactory.getPage(driver, userRolePageClass.class).saveRole()
		 .findUserByEmail(adminRemovesRolesemail)
		.scrollAndClick(0, 0, "//*[text()='"+adminRemovesRolesemail+"']");
		
		MyPageFactory.getPage(driver, userContactInfoPageClass.class).roletab.click();
	
		MyPageFactory.getPage(driver, userRolePageClass.class).removeRole("//span[text()='indexer']"); 
			  MyPageFactory.getPage(driver, userRolePageClass.class).saveRole()
	 		.scrollAndClick(0, 0, "//*[text()='"+adminRemovesRolesemail+"']");
			 
	 		
	 		MyPageFactory.getPage(driver, userContactInfoPageClass.class).roletab.click(); 
			 
	 	
	 		
	 	MyPageFactory.getPage(driver, userRolePageClass.class).assertNotPresent(driver, "//../span[text()='indexer']"); 
	 	driver.get("https://www-dev.krossover.com/intelligence-qa/teams");
		 MyPageFactory.getPage(driver, internalPageClass.class).logout();
	 		
	 		
			 
			 
			 	 
		
	
	}
	
	
	@Test (priority=6)
	  public void SACreatesNewCoach() {
			
			goToMainPage();
			checkPage();
			MyPageFactory.getPage(driver, loginPageClass.class).loginAs(saEmail, saPassword);
			MyPageFactory.getPage(driver, newUserPageClass.class ).createNewUser( adminCreatesNewCoachfirstName, adminCreatesNewCoachlastName, coachEmail,"", "")
			 .chooseRole(headCoachrole)
			 .chooseSport(basketballSport)
			 .chooseTeam("Basketball Team SA")
			 .addRole()
		     .saveRole()
		     .findUserByEmail(coachEmail)
		     .scrollAndClick(0, 0, "//*[text()='"+coachEmail+"']");
			driver.get("https://www-dev.krossover.com/intelligence-qa/teams");
			 MyPageFactory.getPage(driver, internalPageClass.class).logout();
			 }
	
			 
	@Test (priority=7)
		
		public void SACancelsNewUserCreation() {
			
			goToMainPage();
			checkPage();
			MyPageFactory.getPage(driver, loginPageClass.class).loginAs(saEmail, saPassword);
			MyPageFactory.getPage(driver, newUserPageClass.class ).createNewUser("SeleniumFirstNameSA", "SeleniumLastNameSA", saCancelsNewUserCreationemail,"", "");
			MyPageFactory.getPage(driver, userContactInfoPageClass.class ).canceluser.click();
			MyPageFactory.getPage(driver, usersPageClass.class ).findUserByEmail(saCancelsNewUserCreationemail)
			.scrollAndClick2(0, 0, "//*[text()='"+saCancelsNewUserCreationemail+"']");
			driver.get("https://www-dev.krossover.com/intelligence-qa/teams");
			 MyPageFactory.getPage(driver, internalPageClass.class).logout();
			
		 }
	
		
	@Test (priority=8)	
		public void SACreatesAssistantCoach() {
			
			goToMainPage();
			checkPage();
			MyPageFactory.getPage(driver, loginPageClass.class).loginAs(saEmail, saPassword);
			MyPageFactory.getPage(driver, newUserPageClass.class ).createNewUser("SeleniumAssistantCoachFirstNameSA", "SeleniumAssistantCoachLastNameSA", saCreatesAssistantCoachemail,"", "")
			.chooseRole(asCoachrole)
			.chooseSport(footballSport)
			.chooseTeam("Football Team")
			.addRole()
			.saveRole()
			.findUserByEmail(saCreatesAssistantCoachemail)
			.scrollAndClick(0, 0, "//*[text()='"+saCreatesAssistantCoachemail+"']");
			driver.get("https://www-dev.krossover.com/intelligence-qa/teams");
			 MyPageFactory.getPage(driver, internalPageClass.class).logout();
		}
	
	@Test (priority=9)	
		public void SACreatesIndexer() {
			
			goToMainPage();
			checkPage();
			MyPageFactory.getPage(driver, loginPageClass.class).loginAs(saEmail, saPassword);
			MyPageFactory.getPage(driver, newUserPageClass.class ).createNewUser("SeleniumIndexerFirstNameSA", "SeleniumIndexerLastNameSA", saCreatesIndexeremail,"", "")
			.chooseRole(indexerRole);
			MyPageFactory.getPage(driver, userRolePageClass.class).BasketballIndexingBox.click();
			MyPageFactory.getPage(driver, userRolePageClass.class).FootballIndexingBox.click();
			MyPageFactory.getPage(driver, userRolePageClass.class).LacrosseIndexingBox.click();
			MyPageFactory.getPage(driver, userRolePageClass.class).BasketballQABox.click();
			MyPageFactory.getPage(driver, userRolePageClass.class).FootballQABox.click();
			MyPageFactory.getPage(driver, userRolePageClass.class).LacrosseQABox.click();
			
			 
			MyPageFactory.getPage(driver, userRolePageClass.class).addroleButton.click(); //click Add New Role button
			 
			MyPageFactory.getPage(driver, userRolePageClass.class).saveRole()
			.findUserByEmail(saCreatesIndexeremail)
			.scrollAndClick(0, 0, "//*[text()='"+saCreatesIndexeremail+"']");
			driver.get("https://www-dev.krossover.com/intelligence-qa/teams");
			 MyPageFactory.getPage(driver, internalPageClass.class).logout();		
				 
		}
	
	@Test (priority=10)	
		public void SACreatesAthlete() {
			
			goToMainPage();
			checkPage();
			MyPageFactory.getPage(driver, loginPageClass.class).loginAs(saEmail, saPassword);
			MyPageFactory.getPage(driver, newUserPageClass.class ).createNewUser("SeleniumAthleteFirstNameSA", "SeleniumAthleteFirstNameSA", saCreatesAthleteemail,"", "")
			.chooseRole(athleteRole);
		    //driver.findElement(By.xpath("//*[contains(.,'Only coaches can add an athlete to a team roster')]"));
	         
	         
	         MyPageFactory.getPage(driver, userRolePageClass.class).addroleButton.click(); //click Add New Role button
			 
	 		MyPageFactory.getPage(driver, userRolePageClass.class).saveRole()
	 		 
	 		.findUserByEmail(saCreatesAthleteemail)
	 		.scrollAndClick(0, 0, "//*[text()='"+saCreatesAthleteemail+"']");
	 		driver.get("https://www-dev.krossover.com/intelligence-qa/teams");
	 		MyPageFactory.getPage(driver, internalPageClass.class).logout();
	 		
	        
	 		
	 		
	}
	
		
	@Test (priority=11)
		public void SARemovesRoles() {
			
			goToMainPage();
			checkPage();
			MyPageFactory.getPage(driver, loginPageClass.class).loginAs(saEmail, saPassword);
			MyPageFactory.getPage(driver, newUserPageClass.class ).createNewUser("SeleniumFirstName", "SeleniumLastName", saRemovesRolesemail,"1234567890", "1234567890")
		    .chooseRole(athleteRole);
			MyPageFactory.getPage(driver, userRolePageClass.class).addroleButton.click();
			 
			MyPageFactory.getPage(driver, userRolePageClass.class).chooseRole(indexerRole);
			MyPageFactory.getPage(driver, userRolePageClass.class).addroleButton.click(); //click Add New Role button
			
			
			MyPageFactory.getPage(driver, userRolePageClass.class).saveRole();
			
			MyPageFactory.getPage(driver, usersPageClass.class).scrollAndClick(0, 0, "//*[text()='"+saRemovesRolesemail+"']");
			
			MyPageFactory.getPage(driver, userContactInfoPageClass.class).roletab.click();
		
			MyPageFactory.getPage(driver, userRolePageClass.class).removeRole("//span[text()='indexer']"); 
				  MyPageFactory.getPage(driver, userRolePageClass.class).saveRole()
				 
		         
				  .findUserByEmail(saRemovesRolesemail);
		       
				  MyPageFactory.getPage(driver, usersPageClass.class).scrollAndClick(0, 0, "//*[text()='"+saRemovesRolesemail+"']");
				 
		 		
		 		MyPageFactory.getPage(driver, userContactInfoPageClass.class).roletab.click(); 
				 
		 	
		 		
		 	MyPageFactory.getPage(driver, userRolePageClass.class).assertNotPresent(driver, "//../span[text()='indexer']");
		 		
		 	driver.get("https://www-dev.krossover.com/intelligence-qa/teams");
	 		MyPageFactory.getPage(driver, internalPageClass.class).logout();
	 		
				 
				 
				 	 
			
		
		}
} 
	
	
	

	